# -*- coding: latin-1 -*-
# Autor    Lauro Moura
#          Pablo José da Silva

# -----------------------------------------------------------------------------
# mini_java_semantic.py
# -----------------------------------------------------------------------------

import mini_java_parser

class Scope:
    def __init__(self):
        self.var = []
        self.const = []
        self.next = None
        self.prev = None

class Semantic:
    '''globalScope = None
    currentScope = None'''


    def __init__(self):
        self.globalScope = Scope()
        self.currentScope = self.globalScope

    def evaluateProgram(self,node):

        self.evaluateClassDeclaration(node.children[0])
   
    def evaluateClassDeclaration(self, node):
	
	self.evaluateIdentifier(node.children[1]) 
	self.evaluateClassBody(node.children[0])

    def evaluateClassBody(self, node):
	
	self.evaluateClassMemberDeclarationList(node.children[1])

    def evaluateClassMemberDeclarationList(self, node):

	if len(node) == 2:
		self.evaluateClassMemberDeclaration(node.children[0])
		self.evaluateClassMemberDeclarationList(node.children[1])
		
	else:
		print 'debug' # empty??


    def evaluateClassMemberDeclaration(self, node):
	
	if node.type == 'FieldDeclaration':
		self.evaluateFieldDeclaration(node.children[0])

	if node.type == 'MethodDeclaration':
		self.evaluateMethodDeclaration(node.children[0])

   
    def evaluateFieldDeclaration(self, node):
	
	self.evaluateIdentifier(node.children[0])
	self.evaluateType(node.children[1])

    def evaluateType(self, node):
	
	self.evaluatePrimitiveType(node.children[0])


    def evaluatePrimitiveType(self, node):

	print 'teste'
		


		
	

